{% extends '__base.tpl' %}

{% block head %}
<!-- build:css -->
<link rel="stylesheet" href="../../../public/css/page/login.css">
<!-- endbuild -->
{% endblock %}

{% block body %}
<div id='box'>
    <div class="regis">
        <h1><img src="../../../public/images/leftTitle.jpg"></h1>
        <div class="regisDiv" >
            <span class="login-item">
                <img src="../../../public/images/regisLeft.jpg">
            </span>
            <span class="login-item relative">
                <h3><img src='../../../public/images/logoTag.jpg'>原始账户绑定</h3>
                <div class="form">
                    <div>
                        <input type="number" id="tel" placeholder="手机号" />
                        <div class="wrong-tips">请输入正确的手机号</div>
                        <div class="inputSelect clearfix">
                            <input onkeydown="BASE.keyEnter(bindTel)" type="text" id="code" placeholder="验证码" />
                            <button onclick="BASE.LOGIN.getCode.call(this,6)">获取验证码</button>
                        </div>
                        <input class="regisSubmit" type="button" value="绑定" onclick="bindTel(this)">
                    </div>
                </div>
                <p class="clause">
                    <a href="javascript:;" onclick="skipBind()" class="blue fright" >没有账户跳过绑定</a>
                </p>
            </span>
        </div>
    </div>
</div>
{% endblock %}
{% block script %}
<!--公用js部分-->
{{ super() }}
<script>
    /*跳过绑定*/
    function skipBind() {
        var search = location.href.split('?access_token=').pop();
        var openId= search.split('&openId=').pop();
        var accessToken= search.split('&openId=')[0];
        BASE.getHttp('/device/member/wxLogin', {accessToken:accessToken, code:'newuser',openId:openId,skipBind:true },function (res) {
            if(res.code !== 200){
                BASE.clearpop(res.message||'授权登录失败');
                return;
            }
            BASE.LOGIN.loginSuccess(res);
        })
    }
    /*绑定*/
    function bindTel(obj) {
        var search = location.href.split('?access_token=').pop();
        var openId= search.split('&openId=').pop();
        var accessToken= search.split('&openId=')[0];
        var sendData = {
            mobile:$('#tel').val().trim(),
            vcode:$('#code').val().trim(),
            openId:openId,
            skipBind:false,
            code:'newuser',
            accessToken:accessToken,
        };
        if(!sendData.mobile){
            BASE.clearpop('请输入手机号');
            return;
        }
        if(!sendData.vcode){
            BASE.clearpop('请填写验证码');
            return;
        }
        $(obj).attr('disabled',true);
        BASE.getHttp('/device/member/wxLogin', sendData,function (res) {
            $(obj).attr('disabled',false);
            if(res.code !== 200){
                BASE.clearpop(res.message||'绑定失败');
                return;
            }
            BASE.LOGIN.loginSuccess(res);
        })
    }
</script>
{% endblock %}
